package com.dongdongshop.service.impl;

import com.dongdongshop.mapper.TbBrandMapper;
import com.dongdongshop.page.PageBean;
import com.dongdongshop.pojo.TbBrand;
import com.dongdongshop.service.BrandService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
@DubboService
public class BrandServiceImpl implements BrandService {

    @Resource
    private TbBrandMapper tb;


    @Override
    public List<TbBrand> ListBrands() {
        return tb.selectByExample(null);
    }

    @Override
    public PageBean<TbBrand> getAll(Integer pageNum,Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<TbBrand> tbBrands = tb.selectByExample(null);
        PageInfo<TbBrand> p = new PageInfo<>(tbBrands);
        return new PageBean<>(pageNum,pageSize,p.getTotal(),p.getPages(),p.getList());
    }

    @Override
    public int insert(TbBrand b) {
        return tb.insert(b);
    }

    @Override
    public TbBrand getById(Long id) {
        return tb.selectByPrimaryKey(id);
    }

    @Override
    public int update(TbBrand b) {
        return tb.updateByPrimaryKeySelective(b);
    }

    @Override
    public int delete(Long id) {
        return tb.deleteByPrimaryKey(id);
    }

    @Override
    public int deleteCheck(Long[] ids) {
        for (Long id : ids) {
            delete(id);
        }
        return 1;
    }
}
